package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.pojo.BaseCategory1;
import com.atguigu.gmall.product.pojo.BaseCategory2;
import com.atguigu.gmall.product.pojo.BaseCategory3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseManageController {
    @Autowired
    BaseCategory1Service baseCategory1Service;

    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;

    //http://192.168.200.1/admin/product/getCategory1

    /**
     * 获取商品的一级分类
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> list =  baseCategory1Service.getAll();
        return Result.ok(list);
    }

    //http://api.gmall.com/admin/product/getCategory2/{category1Id}

    /**
     * 查询商品列表 2级 菜单信息
     * @param category1Id
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable String category1Id){
        List<BaseCategory2> list = baseCategory2Service.getAll(category1Id);
        return Result.ok(list);
    }

    //http://api.gmall.com/admin/product/getCategory3/{category2Id}

    /**
     * 查询列表中 三级分类的商品信息
     * @param category2Id
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable String category2Id){
        List<BaseCategory3> list = baseCategory3Service.getAll(category2Id);
        return Result.ok(list);
    }



}
